﻿using System.Web.Mvc;
using System;

namespace MvcDependency
{
    public class RenderDependenciesFilter : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if(filterContext.IsChildAction)
                return;

            var response = filterContext.HttpContext.Response;
            response.Filter = new RenderDependenciesStream(response.Filter, 
                DependencyManager.Get(filterContext.HttpContext),
                filterContext.HttpContext.Response.ContentEncoding);
        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
        }
    }
}